package com.hzdesk.media.koreabatchmatvector.logic.persenter;

import android.content.Context;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

import com.hzdesk.media.koreabatchmatvector.R;
import com.hzdesk.media.koreabatchmatvector.config.AppConfig;
import com.hzdesk.media.koreabatchmatvector.logic.contract.MeetingNameContract;
import com.hzdesk.media.koreabatchmatvector.utils.SharedPreferencesUtils;

/**
 * Created by Administrator on 2018/7/12.
 */

public class MeetingNamePersenter implements MeetingNameContract.IMeetingPersenter{
    private MeetingNameContract.IMeetingNameView IMeetingNameView;
    private Context mContext;

    public MeetingNamePersenter(MeetingNameContract.IMeetingNameView IMeetingNameView) {
        this.IMeetingNameView = IMeetingNameView;
    }

    @Override
    public void initView(Context context) {
        mContext=context;
        String name= SharedPreferencesUtils.getMeetingName(mContext);
        IMeetingNameView.setEditTextName(name);

    }

    @Override
    public void onClickCancle() {
        IMeetingNameView.cancle();

    }

    @Override
    public void onClickOk() {
        IMeetingNameView.confim();

    }

    @Override
    public void setOnHoverListenerAndOnFocusChangeListener(Button button) {
        button.setOnHoverListener(onHoverListener);
        button.setOnFocusChangeListener(onFocusChangeListener);

    }

    private View.OnHoverListener onHoverListener = new View.OnHoverListener() {
        @Override
        public boolean onHover(View v, MotionEvent event) {
            switch (event.getAction()) {
                case MotionEvent.ACTION_HOVER_ENTER:
                    v.requestFocus();
                    v.requestFocusFromTouch();
                    break;
                case MotionEvent.ACTION_HOVER_EXIT:
                    break;
                case MotionEvent.ACTION_HOVER_MOVE:
                    break;
            }
            return false;
        }
    };

    private View.OnFocusChangeListener onFocusChangeListener=new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            Button button= (Button) v;
            if (hasFocus){
                button.setBackgroundResource(R.drawable.dialog_mouse_set_button_bg_light);
            }else {
                button.setBackgroundResource(R.drawable.dialog_mouse_set_button_bg);
            }

        }
    };

}
